package com.ccc.boot.security.config;

import com.ccc.boot.security.util.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.io.Serializable;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * 公钥私钥配置类
 *
 * @author superC
 * @date 2022/3/23
 * @version 0.1.0
 */

@Data
@ConfigurationProperties("base.rsa.key")
public class RsaKeyProperties implements Serializable {

    private static final long serialVersionUID = 8469172448696427223L;

    private String pubKeyPath;

    private String priKeyPath;

    private PublicKey publicKey;

    private PrivateKey privateKey;

    @PostConstruct
    public void createKey() throws Exception {
        this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
    }

}
